package com.haha.FileCode;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class TestFileCopy {
    public static void main(String[] args) throws IOException{
        String source="E:\\gulimail\\nettystudy\\data.txt";
        String target="E:\\gulimail\\nettystudy\\to.txt";
        try {
            Files.walk(Paths.get(source)).forEach(path -> {
                String targetName = path.toString().replace(source,target);
                if(Files.isDirectory(path)){
                    try {
                        Files.createDirectory(Paths.get(targetName));
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }else if(Files.isRegularFile(path)){
                    try {
                        Files.copy(path,Paths.get(targetName));
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            });
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
